package org.hawk.gwtppc.webtest.tests.classsuite;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.WildcardType;
import java.util.List;
import java.util.RandomAccess;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.GenericClassMock;
import org.hawk.gwtppc.webtest.tests.mock.GenericInterfaceMock1;
import org.hawk.gwtppc.webtest.tests.mock.GenericInterfaceMock2;
import org.hawk.gwtppc.webtest.tests.mock.InterfaceMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock1;

public class GetGenericInterfacesTest implements Test {

	public void run() throws Throwable {
		Asserts.assertEquals(SubClassMock1.class.getGenericInterfaces().length, 3);
		Asserts.assertEquals(SubClassMock1.class.getGenericInterfaces()[0], InterfaceMock.class);
		Asserts.assertEquals(SubClassMock1.class.getGenericInterfaces()[1], Serializable.class);
		Asserts.assertEquals(SubClassMock1.class.getGenericInterfaces()[2], RandomAccess.class); 
		
		Asserts.assertEquals(GenericClassMock.class.getGenericInterfaces().length, 2);
		
		ParameterizedType i1 = (ParameterizedType) GenericClassMock.class.getGenericInterfaces()[0];
		Asserts.assertFalse(i1 == null);
		Asserts.assertEquals(i1.toString(), "org.hawk.gwtppc.webtest.tests.mock.GenericInterfaceMock1<java.lang.String, java.lang.Integer>");
		Asserts.assertEquals(i1.getActualTypeArguments().length, 2);
		Asserts.assertTrue(i1.getOwnerType() == null);
		Asserts.assertEquals(i1.getRawType(), GenericInterfaceMock1.class);
		Asserts.assertEquals(i1.getActualTypeArguments()[0], String.class);
		Asserts.assertEquals(i1.getActualTypeArguments()[1], Integer.class);
		
		ParameterizedType i2 = (ParameterizedType) GenericClassMock.class.getGenericInterfaces()[1];
		Asserts.assertFalse(i2 == null);
		Asserts.assertEquals(i2.toString(), "org.hawk.gwtppc.webtest.tests.mock.GenericInterfaceMock2<" +
				"java.lang.Object, java.util.List<? super java.lang.Integer>>");
		Asserts.assertEquals(i2.getActualTypeArguments().length, 2);
		Asserts.assertTrue(i2.getOwnerType() == null);
		Asserts.assertEquals(i2.getRawType(), GenericInterfaceMock2.class);
		Asserts.assertEquals(i2.getActualTypeArguments()[0], Object.class);
		
		ParameterizedType param = (ParameterizedType) i2.getActualTypeArguments()[1];
		Asserts.assertFalse(param == null);
		Asserts.assertEquals(param.toString(), "java.util.List<? super java.lang.Integer>");
		Asserts.assertEquals(param.getActualTypeArguments().length, 1);
		Asserts.assertTrue(param.getOwnerType() == null);
		Asserts.assertEquals(param.getRawType(), List.class);
		
		WildcardType wild = (WildcardType) param.getActualTypeArguments()[0];
		Asserts.assertEquals(wild.getUpperBounds().length, 1);
		Asserts.assertEquals(wild.getUpperBounds()[0], Object.class);
		Asserts.assertEquals(wild.getLowerBounds().length, 1);
		Asserts.assertEquals(wild.getLowerBounds()[0], Integer.class);
	}

	public String getName() {
		return "getGenericInterfaces()";
	}

}
